$(document).ready(function(){
	$(".maintitle").bind("click",function(){
			if($(this).next().css("display")=='none'){
				$(this).css({'background-image':'url(/images/display_button.gif)'});
				$(this).next().slideDown(250);
			}else{
						$(this).css({'background-image':'url(/images/hide_button.gif)'});
						$(this).next().slideUp(250);
				}
		});
	if($.trim($(".tablesorter tbody").text())=='')
	{
		$(".notddata").html("暂无数据");
	}else{
		$(".notddata").parent().remove();
	}
	
	$(".maintitle").hover(
			function () {
	    	$(this).addClass("hover");
		  },
		  function () {
		    $(this).removeClass("hover");
		  }
	  );
	  
	   $(".submenu li").addClass("bluebackgroundout");
	  
	   
	   var hrefArray = new Array();
	   var hrefIndex = 0;
	   $.each($(".submenu li a"),function(){
	   			hrefArray[hrefIndex] = $(this).attr("href");
	   			hrefIndex++;
	   });
	   var findLi = false;
	   $.each($(".submenu li a"),function(){
	   		if(window.location.href.indexOf(returnUrl($(this).attr("href")))>-1)
	   			{
	   			$(this).parent().addClass("currentBg");
	   			findLi=true;
	   			}
	   });
	   if(!findLi)
	   {
	   		$.each($(".submenu li a"),function(){
	   		if(window.location.pathname.indexOf(	$(this).attr("href").substring(	0,($(this).attr("href").substring(1).lastIndexOf('/')+1)))>-1	)
	   			{
	   				if(!findLi)
		   			$(this).parent().addClass("currentBg");
		   			findLi=true;
	   			}
	   		});
	   }
	   
	   
	   $(".submenu li").hover(
			function () {
	    	$(this).addClass("bluebackgroundover");
	    	$(this).removeClass("bluebackgroundout");
		  },
		  function () {
		  	$(this).removeClass("bluebackgroundover");
		  	$(this).addClass("bluebackgroundout");
		  }
		  );
	  
	 // $(".submenu").hide();
	  var menu_index=0;
	
	 	 menu_index=0;
	    $.each( $(".maintitle"),function(){
	  		menu_index++;
	  		if(menu_index>=4)
	  			$(this).addClass("maintitlebgh");
	  		else
	  			$(this).addClass("maintitlebgs");
	  	});
		
		
			
	});
function submit(num){

document.forms[num].submit();

}
function ajaxPostRequest(url,param,resultFun)
{
$.ajax({
	  url: url,
	  cache: false,
	  data: param,
	  type:"post",
	  success: function(html){
		 resultFun.call(resultFun.call,html);
	  }
	}); 
}

function asynchronousAjaxPostRequest(url,param,resultFun)
{
	$.ajax({
		  url: url,
		  cache: false,
		  data: param,
		  type:"post",
		  async:false,
		  success: function(html){
			 resultFun.call(resultFun.call,html);
		  }
		}); 
	
}

function copy_clip(copy){
  	if($.browser.safari){alert('不支持谷歌浏览器JS复制，请手动复制！');return;};
	if (window.clipboardData){
	window.clipboardData.setData("Text", copy);}
	else if (window.netscape){
	netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
	var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
	if (!clip) return;
	var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
	if (!trans) return;
	trans.addDataFlavor('text/unicode');
	var str = new Object();
	var len = new Object();
	var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
	var copytext=copy;
	str.data=copytext;
	trans.setTransferData("text/unicode",str,copytext.length*2);
	var clipid=Components.interfaces.nsIClipboard;
	if (!clip) return false;
	clip.setData(trans,null,clipid.kGlobalClipboard);}
	alert("已复制"+copy)
	return false;
	}

function returnUrl(href)
{
	return href.substring(0,href.indexOf("shtml")+5);
}

function lightMenuBg()
{
	
	var findLi = false;
	var locationhref = window.location.pathname;

	   $.each($(".submenu li a"),function(){
	   	
	   	if(locationhref.indexOf(	 returnUrl($(this).attr("href"))	 )>-1)
   			{
	   			$(this).parent().addClass("currentBg");
	   			findLi=true;
   			}
	   });

	   if(!findLi)
	   {
	   
	   		$.each($(".submenu li a"),function(){
	   		if(window.location.pathname=='/kf/chatdetail.shtml' && returnUrl($(this).attr("href"))=='/kf/receptotal.shtml')
		   	{
		   		$(this).parent().addClass("currentBg");
		   		findLi=true;
		   		}
	   		});
	   		
	   		
	   		$.each($(".submenu li a"),function(){
	   		if(locationhref.indexOf(	$(this).attr("href").substring(	0,($(this).attr("href").substring(1).lastIndexOf('/')+1)))>-1	|| window.location.pathname=='')
	   			{
	   				if(!findLi)
		   			$(this).parent().addClass("currentBg");
		   			findLi=true;
	   			}
	   		});
	   }

}



function freshTableList(mtr)
{	
	if(tablelist=='')
	return ;
	tablelist=mtr+tablelist;
	$("#myTable tbody").html(tablelist);
	$("#myTable th").unbind("click");
	$(".first").unbind("click");
	$(".prev").unbind("click");
	$(".next").unbind("click");
	$(".last").unbind("click");
	$(".tablesorter").tablesorter({widgets: ['zebra']}).tablesorterPager({container: $("#pager"), positionFixed: false});
}

    Date.prototype.format = function(format)  
{  
   var o = {  
     "M+" : this.getMonth()+1, //month  
     "d+" : this.getDate(),    //day  
     "h+" : this.getHours(),   //hour  
     "m+" : this.getMinutes(), //minute  
     "s+" : this.getSeconds(), //second  
     "q+" : Math.floor((this.getMonth()+3)/3), //quarter  
     "S" : this.getMilliseconds() //millisecond  
   }  
   if(/(y+)/.test(format)) format=format.replace(RegExp.$1,  
     (this.getFullYear()+"").substr(4 - RegExp.$1.length));  
   for(var k in o)if(new RegExp("("+ k +")").test(format))  
     format = format.replace(RegExp.$1,  
       RegExp.$1.length==1 ? o[k] :    
         ("00"+ o[k]).substr((""+ o[k]).length));  
   return format;  
}
    function loadUrl(url)
    {
    	if($.trim(url)!='')
    	window.location.href=url;
    }
